package com.wetao.module_user.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatTextView;

import com.wetao.lib_common.base.BaseLazyFragment;
import com.wetao.lib_common.utils.BaseEvent;
import com.wetao.lib_common.utils.ConstantUtils;
import com.wetao.lib_common.view.OnMultiClickListener;
import com.wetao.module_user.R;
import com.wetao.module_user.contract.UserUpgradeFragmentCon;
import com.wetao.module_user.presenter.UserUpgradeFragmentPre;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class UserUpgradeFragment extends BaseLazyFragment<UserUpgradeFragmentCon.View, UserUpgradeFragmentPre> implements
        UserUpgradeFragmentCon.View {


    public static UserUpgradeFragment newInstance(/*String className, Integer classId*/) {
        Bundle args = new Bundle();
        /*args.putString("className", className);
        args.putInt("classId", null == classId ? -1 : classId);*/

        UserUpgradeFragment fragment = new UserUpgradeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.user_fragment_upgrade;
    }

    @Override
    public UserUpgradeFragmentPre createPresenter() {
        return new UserUpgradeFragmentPre(mContext);
    }

    @Override
    public UserUpgradeFragmentCon.View createView() {
        return this;
    }

    @Override
    public void init(View rootView) {
        Bundle bundle = null;
        if ((bundle = getArguments()) != null) {
            /*String className = bundle.getString("className");
            if(!TextUtils.isEmpty(className)) {
                tvClassAdmin.setText(className);
            }
            int classId = bundle.getInt("classId");*/
        }

        ((AppCompatTextView)rootView.findViewById(R.id.tv_version_name))
                .setText(String.format(getResources().getString(R.string.user_version_tip), ConstantUtils.getAppVersionName()));
        ((AppCompatButton)rootView.findViewById(R.id.tv_check_version))
                .setOnClickListener(new OnMultiClickListener() {
                    @Override
                    public void onMultiClick(View v) {
                        if(null != onListenClick) {
                            onListenClick.onListenUpgradeClick();
                        }
                    }
                });

    }

    @Override
    public void onFragmentFirst() {
        super.onFragmentFirst();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void onFragmentInVisible() {
        super.onFragmentInVisible();
    }

    @Override
    public void onFragmentVisble() {
        super.onFragmentVisble();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void onEventReceived(BaseEvent event) {
        if (event.getCode() == 1) {//退出登录  刷新列表

        }
    }

    public interface OnListenClick{
        void onListenUpgradeClick();
    }
    OnListenClick onListenClick;

    public void setOnListenClick(OnListenClick onListenClick) {
        this.onListenClick = onListenClick;
    }
}
